public class LC600D {
    public int findIntegers(int n) {
        if(n==1)return 2;
        return findZero(n,1)+2;
    }
    public int findZero(int n,int count){
        count=count<<1;
        if (count<=n){
            return findZero(n,count)+findOne(n,count)+1;
        }
        return 0;
    }

    public int findOne(int n,int count){
        count=(count<<1)+1;
        if (count<=n){
            return findZero(n,count)+1;
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(new LC600D().findIntegers(5));
    }
}
